﻿@*
    // Copyright (c) Alex Reich.
    // Licensed under the CC BY 4.0 License.
*@
@using RulesEngineEditor.Models
@inject RulesEngineEditor.Services.WorkflowService WorkflowService

<EditForm EditContext="@EditContext">
    <DataAnnotationsValidator />
    <ValidationSummary />
    <sp_grid_scopedparam>
        <div>
            <InputText title="Parameter Name" class="form-control" @bind-Value="@scopedParam.Name" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
        </div>
        <div>
            <InputTextArea title="Expression" rows="5" form="Expression" class="form-control" @bind-Value="@scopedParam.Expression" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
        </div>
        <div>
            <button @onclick="@(e => ScopedParamDelete.InvokeAsync(scopedParam))" class="btn btn-secondary m-1">
                <span class="oi oi-trash"></span>
            </button>
        </div>
    </sp_grid_scopedparam>
</EditForm>
@code {
    [Parameter]
    public ScopedParamData scopedParam { get; set; }

    [Parameter]
    public EventCallback<ScopedParamData> ScopedParamDelete { get; set; }

    private EditContext EditContext;

    protected override void OnInitialized()
    {
        EditContext = new EditContext(scopedParam);
        EditContext.OnFieldChanged += EditContext_OnFieldChanged;

        base.OnInitialized();
    }

    private void EditContext_OnFieldChanged(object sender, FieldChangedEventArgs e)
    {
        WorkflowService.WorkflowUpdate();
    }
}
